import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:finance_app/src/entities/chat_room_message_entity.dart';
import 'package:finance_app/src/widgets/chat_room/text_chat_item.dart';
import 'package:finance_app/src/widgets/chat_room/video_chat_item.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'image_chat_item.dart';

class RightChatItem extends StatelessWidget {
  final List<ChatRoomMessageEntity> contents;
  final String time;

  const RightChatItem({Key key, this.contents, this.time}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextChatItemStyle.right(
      child: Padding(
        padding: EdgeInsets.only(right: getDp(25), top: getDp(7)),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.end,
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            Expanded(
                child: Column(
              crossAxisAlignment: CrossAxisAlignment.end,
              mainAxisSize: MainAxisSize.min,
              children: List.generate(contents.length, (index) {
                final item = contents[index];
                Widget msgWidget;
                if (item.type == 'image') {
                  msgWidget = ImageChatItem(
                    isTop: index == 0,
                    id: item.id,
                    content: item.content,
                    actions: item.actions,
                  );
                } else if (item.type == 'video') {
                  msgWidget = VideoChatItem(
                    isTop: index == 0,
                    content: item.content,
                    actions: item.actions,
                  );
                } else {
                  msgWidget = TextChatItem(
                    isTop: index == 0,
                    content: item.content,
                    actions: item.actions,
                  );
                }
                return item.id == null
                    ? Stack(
                        children: [
                          msgWidget,
                          Positioned(
                              bottom: 0,
                              right: 0,
                              child: CupertinoActivityIndicator()),
                        ],
                      )
                    : msgWidget;
              })
                ..add(Padding(
                  padding: EdgeInsets.only(left: getDp(13), top: getDp(10)),
                  child: Text(
                    time,
                    style: TextStyle(
                      color: aceDarkGrayColor70,
                      fontSize: getSp(12),
                      fontWeight: FontWeight.w400,
                      height: 22 / 12,
                    ),
                  ),
                )),
            )),
          ],
        ),
      ),
    );
  }
}
